home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java Primer Plus
/
Java Primer Plus (Waite Group Proess)(1996).iso
/
chapter8
/
MyJavaApp.java
< prev
next >
Wrap
Text File
|
1995-12-31
|
2KB
|
77 lines
/* ------------ Start of Code -----------------*/
import java.applet.*;
import java.awt.*;
/* ------------ MyJavaApp Class -----------------*/
public class MyJavaApp extends Applet implements Runnable {
aline myline = new aline(300);
int angle=0;
int anglemod = 8;
Thread mythread=null;
/* ------------ Thread methods -----------------*/
public void run() {
while (true) {
repaint();
try {
Thread.sleep(50);
} catch (java.lang.InterruptedException e) {}
}
}
/* ------------ Applet Methods -----------------*/
public void start() {
if (mythread == null) {
mythread = new Thread(this);
mythread.start();
}
}
public void stop() {
if (mythread != null) {
mythread.stop();
mythread=null;
}
}
public void init() // define init method
{
resize(300,300);
}
public void paint(Graphics g) // define paint method
{
g.setColor(Color.lightGray); // set color
g.drawLine(myline.rx[0],myline.ry[0], // erase line
myline.rx[1],myline.ry[1]);
myline.rotate(angle); // rotate the line then
angle += anglemod; // increase the angle
if (angle>360) angle -= 360;
g.setColor(Color.black); // set color
g.drawLine(myline.rx[0],myline.ry[0], // draw line
myline.rx[1],myline.ry[1]);
}
public boolean mouseDown(Event e,int x, int y)
{ anglemod =- anglemod;
return true;
}
}